#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Time       :   21:50
# Author     : Y4
# Site       : 
# File       : 011 线程之间的通讯.py
# Software   : PyCharm

import random

import queue

import threading

import time

def produce(q):
    i = 0
    while i < 10:
        n = random.randint(1,100)
        q.put("生产者生产的数据:{}".format(n))
        print("生产者生产的数据:{}".format(n))
        time.sleep(1)
        i += 1
    q.put(None)
    # 完成任务
    q.task_done()


def consume(q):
    while True:
        item = q.get()
        if item is None:
            break
        print("消费者获取到:{}".format(item))
        time.sleep(4)
    # 完成任务
    q.task_done()


if __name__ == '__main__':
    q = queue.Queue(10)
    arr = []

    # 创建生产者
    t1 = threading.Thread(target=produce,args=(q,))
    t1.start()


    # 创建消费者
    t2 = threading.Thread(target=consume,args=(q,))
    t2.start()

    t1.join()
    t2.join()

    print('end')